package com.swallow.user.controller;

import com.swallow.common.result.RetVal;
import com.swallow.user.entity.dto.UserDto;
import com.swallow.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @program:cloud_demo
 * @author: 马雨清
 * @Time: 2025/4/20  0:59
 * @description:
 */
@RequestMapping("/user")
@RestController
public class UserController {

    /**
     * 用户注册
     * @param user 用户
     * @return
     */
    @Autowired
    private UserService userService;
    @PutMapping("/register")
    public RetVal register(@RequestBody UserDto userDto){
        Boolean result = userService.register(userDto);
        if (!result){
            return RetVal.build(null,5001,"注册失败");
        }
        return RetVal.ok();
    }


    @Autowired
    private RedisTemplate redisTemplate;
    @GetMapping("/insertCache")
    public void insertCache(){
        redisTemplate.opsForValue().set("testKey1","testValue");
    }

    @PostMapping("/login")
    public RetVal login(@RequestBody HashMap<String,String> map){
        Long userid = userService.login(map);
        return RetVal.ok(userid);
    }

    @PutMapping("/insert")
    public void insertOrder(){

    }
}
